/*     */ package com.qmsk.business.store.rack.controller;
/*     */ 
/*     */ import com.qmsk.business.store.rack.dao.RackDao;
/*     */ import com.utils.basic.MapUtils;
/*     */ import com.utils.basic.ObjectComm;
/*     */ import com.utils.gson.in.GsonHeadOneRow;
/*     */ import com.utils.gson.in.ParserDataSetJson;
/*     */ import com.utils.gson.out.GsonEbRst;
/*     */ import com.utils.jdbc.connection.DbConnection;
/*     */ import com.utils.web.RequestUtils;
/*     */ import com.utils.web.ResponseUtils;
/*     */ import java.io.IOException;
/*     */ import java.sql.SQLException;
/*     */ import java.util.HashMap;
/*     */ import java.util.Map;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import org.apache.log4j.Logger;
/*     */ import org.springframework.beans.factory.annotation.Autowired;
/*     */ import org.springframework.stereotype.Controller;
/*     */ import org.springframework.transaction.annotation.Transactional;
/*     */ import org.springframework.web.bind.annotation.PathVariable;
/*     */ import org.springframework.web.bind.annotation.RequestMapping;
/*     */ 
/*     */ @Controller
/*     */ @RequestMapping({"/rack"})
/*     */ public class RackController
/*     */ {
/*  37 */   private static final Logger logger = Logger.getLogger(RackController.class);
/*     */ 
/*     */   @Autowired
/*     */   private RackDao dao;
/*     */ 
/*     */   @RequestMapping(value={"find/shopId/{shopId}/opt/{pageIdx}/{pageSize}"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*     */   public void getListOptShopId(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") String shopId, @PathVariable("pageIdx") Integer nPageIdx, @PathVariable("pageSize") Short nPageSize)
/*     */   {
/*  57 */     nPageSize = RequestUtils.getRequestValidPageSize(nPageSize);
/*     */     try {
/*  59 */       Map params = new HashMap();
/*  60 */       MapUtils.addToMap(params, "id", RequestUtils.getLong(request, "id"));
/*  61 */       MapUtils.addToMap(params, "hId", 
/*  62 */         RequestUtils.getLong(request, "hId"));
/*  63 */       MapUtils.addToMap(params, "status", 
/*  64 */         RequestUtils.getShort(request, "status"));
/*     */ 
/*  66 */       MapUtils.addPercentToMap(params, "name", 
/*  67 */         RequestUtils.getString(request, "name"));
/*  68 */       MapUtils.addPercentToMap(params, "code", 
/*  69 */         RequestUtils.getString(request, "code"));
/*     */ 
/*  71 */       GsonEbRst gsonEbRst = this.dao.getGsonOfAll(params, nPageIdx, nPageSize);
/*  72 */       ResponseUtils.setResponseResult(gsonEbRst, response);
/*     */     } catch (SQLException e) {
/*  74 */       logger.error(e);
/*  75 */       ResponseUtils.setErrorMsgResponse(
/*  76 */         RequestUtils.getFindDataErrorMessage(request), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @RequestMapping(value={"find/shopId/{shopId}/id/{id}"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*     */   public void getListOfId(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") String shopId)
/*     */   {
/*     */     try {
/*  84 */       Map params = new HashMap();
/*  85 */       MapUtils.addToMap(params, "id", RequestUtils.getLong(request, "id"));
/*  86 */       MapUtils.addToMap(params, "hId", 
/*  87 */         RequestUtils.getLong(request, "hId"));
/*  88 */       MapUtils.addToMap(params, "status", 
/*  89 */         RequestUtils.getShort(request, "status"));
/*     */ 
/*  91 */       MapUtils.addPercentToMap(params, "name", 
/*  92 */         RequestUtils.getString(request, "name"));
/*  93 */       MapUtils.addPercentToMap(params, "code", 
/*  94 */         RequestUtils.getString(request, "code"));
/*  95 */       GsonEbRst gsonEbRst = this.dao.getGsonOfId(params);
/*  96 */       ResponseUtils.setResponseResult(gsonEbRst, response);
/*     */     } catch (SQLException e) {
/*  98 */       logger.error(e);
/*  99 */       ResponseUtils.setErrorMsgResponse(
/* 100 */         RequestUtils.getFindDataErrorMessage(request), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @RequestMapping(value={"find/shopId/{shopId}/hId/{hId}/{pageIdx}/{pageSize}"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*     */   public void getListOfHouseId(HttpServletRequest request, HttpServletResponse response, @PathVariable("hId") Long hId, @PathVariable("pageIdx") Integer nPageIdx, @PathVariable("pageSize") Short nPageSize)
/*     */   {
/*     */     try
/*     */     {
/* 110 */       Map params = new HashMap();
/* 111 */       MapUtils.addToMap(params, "hId", hId);
/*     */ 
/* 113 */       GsonEbRst gsonEbRst = this.dao.getGsonOfAll(params, nPageIdx, nPageSize);
/* 114 */       ResponseUtils.setResponseResult(gsonEbRst, response);
/*     */     } catch (SQLException e) {
/* 116 */       logger.error(e);
/* 117 */       ResponseUtils.setErrorMsgResponse(
/* 118 */         RequestUtils.getFindDataErrorMessage(request), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @Transactional
/*     */   @RequestMapping(value={"insert/shopId/{shopId}"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void insert(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") Integer shopId)
/*     */     throws IOException
/*     */   {
/*     */     try
/*     */     {
/* 139 */       int nResult = 0;
/* 140 */       String sData = RequestUtils.getStringOfData(request);
/* 141 */       if (!(sData.contains("hId"))) {
/* 142 */         ResponseUtils.setErrorMsgResponse(
/* 143 */           "Foreign key hId(is HouseID) must not be empty", 
/* 144 */           response);
/* 145 */         return;
/*     */       }
/*     */ 
/* 148 */       ParserDataSetJson p = ParserDataSetJson.fromString(sData);
/*     */ 
/* 150 */       nResult = this.dao.applyUpdates(p);
/*     */ 
/* 152 */       if (nResult > 0)
/* 153 */         DbConnection.commit();
/*     */       else {
/* 155 */         DbConnection.rollback();
/*     */       }
/*     */ 
/* 158 */       ResponseUtils.setSqlResultResponse(nResult, 
/* 159 */         RequestUtils.getSqlInsertDataErrorMessage(request), 
/* 160 */         response);
/*     */     } catch (Exception e) {
/* 162 */       DbConnection.rollback();
/* 163 */       logger.error(e);
/* 164 */       ResponseUtils.setErrorMsgResponse(
/* 165 */         RequestUtils.getSqlInsertDataErrorMessage(request) + ":" + 
/* 166 */         e.getMessage(), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @Transactional
/*     */   @RequestMapping(value={"del/shopId/{shopId}"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void delete(HttpServletRequest request, HttpServletResponse response)
/*     */   {
/* 180 */     String id = RequestUtils.getStringOfId(request);
/*     */     try {
/* 182 */       String[] strParams = id.split(",");
/* 183 */       int nResult = this.dao.deleteParams(strParams);
/*     */ 
/* 185 */       if (nResult > 0)
/* 186 */         DbConnection.commit();
/*     */       else {
/* 188 */         DbConnection.rollback();
/*     */       }
/*     */ 
/* 191 */       ResponseUtils.setSqlResultResponse(nResult, 
/* 192 */         RequestUtils.getSqlDeleteDataErrorMessage(request), 
/* 193 */         response);
/*     */     }
/*     */     catch (Exception e) {
/* 196 */       DbConnection.rollback();
/* 197 */       logger.error(e);
/* 198 */       ResponseUtils.setErrorMsgResponse(
/* 199 */         RequestUtils.getSqlDeleteDataErrorMessage(request) + ":" + 
/* 200 */         e.getMessage(), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @Transactional
/*     */   @RequestMapping(value={"edit/shopId/{shopId}"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void update(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") Integer shopId, @PathVariable("id") Long id)
/*     */   {
/*     */     try
/*     */     {
/* 219 */       int nResult = 0;
/* 220 */       String sData = RequestUtils.getStringOfData(request);
/* 221 */       ParserDataSetJson p = ParserDataSetJson.fromString(sData);
/*     */ 
/* 223 */       if ((p != null) && (p.isExistsUpdateRows())) {
/* 224 */         for (GsonHeadOneRow r : p.getListUpdateRows()) {
/* 225 */           Integer status = ObjectComm.objectToInteger(r
/* 226 */             .getValueOfName("status"));
/* 227 */           if ((status == null) || (status.intValue() != 0) || 
/* 229 */             (this.dao.checkStatus(ObjectComm.objectToLong(r
/* 229 */             .getValueOfName("id"))).booleanValue()))
/*     */             continue;
/* 230 */           ResponseUtils.setErrorMsgResponse("请先启用规则", 
/* 231 */             response);
/* 232 */           return;
/*     */         }
/*     */ 
/* 236 */         nResult = this.dao.applyUpdates(p);
/*     */       }
/*     */ 
/* 239 */       if (p != null) {
/* 240 */         nResult = this.dao.applyUpdates(p);
/*     */       }
/*     */ 
/* 243 */       if (nResult > 0)
/* 244 */         DbConnection.commit();
/*     */       else {
/* 246 */         DbConnection.rollback();
/*     */       }
/* 248 */       ResponseUtils.setSqlResultResponse(nResult, 
/* 249 */         RequestUtils.getSqlInsertDataErrorMessage(request), 
/* 250 */         response);
/*     */     } catch (Exception e) {
/* 252 */       logger.error(e);
/* 253 */       DbConnection.rollback();
/* 254 */       ResponseUtils.setErrorMsgResponse(
/* 255 */         RequestUtils.getSqlDeleteDataErrorMessage(request) + ":" + 
/* 256 */         e.getMessage(), response);
/*     */     }
/*     */   }
/*     */ }

/* Location:           C:\Users\Administrator\Desktop\新建文件夹\WEB-INF\classes\
 * Qualified Name:     com.qmsk.business.store.rack.controller.RackController
 * JD-Core Version:    0.5.3
 */